<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>webchannelbasetransport.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_labs_net_webchannel_webchannelbasetransport.js.html">webchannelbasetransport.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2013 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Implementation of a WebChannel transport using WebChannelBase.
<a name="line17"></a> *
<a name="line18"></a> * When WebChannelBase is used as the underlying transport, the capabilities
<a name="line19"></a> * of the WebChannel are limited to what&#39;s supported by the implementation.
<a name="line20"></a> * Particularly, multiplexing is not possible, and only strings are
<a name="line21"></a> * supported as message types.
<a name="line22"></a> *
<a name="line23"></a> */
<a name="line24"></a>
<a name="line25"></a>goog.provide(&#39;goog.labs.net.webChannel.WebChannelBaseTransport&#39;);
<a name="line26"></a>
<a name="line27"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line28"></a>goog.require(&#39;goog.events.EventTarget&#39;);
<a name="line29"></a>goog.require(&#39;goog.labs.net.webChannel.WebChannelBase&#39;);
<a name="line30"></a>goog.require(&#39;goog.log&#39;);
<a name="line31"></a>goog.require(&#39;goog.net.WebChannel&#39;);
<a name="line32"></a>goog.require(&#39;goog.net.WebChannelTransport&#39;);
<a name="line33"></a>goog.require(&#39;goog.string.path&#39;);
<a name="line34"></a>
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>/**
<a name="line38"></a> * Implementation of {@link goog.net.WebChannelTransport} with
<a name="line39"></a> * {@link goog.labs.net.webChannel.WebChannelBase} as the underlying channel
<a name="line40"></a> * implementation.
<a name="line41"></a> *
<a name="line42"></a> * @constructor
<a name="line43"></a> * @struct
<a name="line44"></a> * @implements {goog.net.WebChannelTransport}
<a name="line45"></a> * @final
<a name="line46"></a> */
<a name="line47"></a>goog.labs.net.webChannel.WebChannelBaseTransport = function() {};
<a name="line48"></a>
<a name="line49"></a>
<a name="line50"></a>goog.scope(function() {
<a name="line51"></a>var WebChannelBaseTransport = goog.labs.net.webChannel.WebChannelBaseTransport;
<a name="line52"></a>var WebChannelBase = goog.labs.net.webChannel.WebChannelBase;
<a name="line53"></a>
<a name="line54"></a>
<a name="line55"></a>/**
<a name="line56"></a> * @override
<a name="line57"></a> */
<a name="line58"></a>WebChannelBaseTransport.prototype.createWebChannel = function(
<a name="line59"></a>    url, opt_options) {
<a name="line60"></a>  return new WebChannelBaseTransport.Channel(url, opt_options);
<a name="line61"></a>};
<a name="line62"></a>
<a name="line63"></a>
<a name="line64"></a>
<a name="line65"></a>/**
<a name="line66"></a> * Implementation of the {@link goog.net.WebChannel} interface.
<a name="line67"></a> *
<a name="line68"></a> * @param {string} url The URL path for the new WebChannel instance.
<a name="line69"></a> * @param {!goog.net.WebChannel.Options=} opt_options Configuration for the
<a name="line70"></a> *     new WebChannel instance.
<a name="line71"></a> *
<a name="line72"></a> * @constructor
<a name="line73"></a> * @implements {goog.net.WebChannel}
<a name="line74"></a> * @extends {goog.events.EventTarget}
<a name="line75"></a> * @final
<a name="line76"></a> */
<a name="line77"></a>WebChannelBaseTransport.Channel = function(url, opt_options) {
<a name="line78"></a>  WebChannelBaseTransport.Channel.base(this, &#39;constructor&#39;);
<a name="line79"></a>
<a name="line80"></a>  /**
<a name="line81"></a>   * The underlying channel object.
<a name="line82"></a>   *
<a name="line83"></a>   * @private {!WebChannelBase}
<a name="line84"></a>   */
<a name="line85"></a>  this.channel_ = new WebChannelBase(opt_options);
<a name="line86"></a>
<a name="line87"></a>  /**
<a name="line88"></a>   * The URL of the target server end-point.
<a name="line89"></a>   *
<a name="line90"></a>   * @private {string}
<a name="line91"></a>   */
<a name="line92"></a>  this.url_ = url;
<a name="line93"></a>
<a name="line94"></a>  /**
<a name="line95"></a>   * The test URL of the target server end-point. This value defaults to
<a name="line96"></a>   * this.url_ + &#39;/test&#39;.
<a name="line97"></a>   *
<a name="line98"></a>   * @private {string}
<a name="line99"></a>   */
<a name="line100"></a>  this.testUrl_ = (opt_options &amp;&amp; opt_options.testUrl) ? opt_options.testUrl :
<a name="line101"></a>      goog.string.path.join(this.url_, &#39;test&#39;);
<a name="line102"></a>
<a name="line103"></a>  /**
<a name="line104"></a>   * The logger for this class.
<a name="line105"></a>   * @private {goog.log.Logger}
<a name="line106"></a>   */
<a name="line107"></a>  this.logger_ = goog.log.getLogger(
<a name="line108"></a>      &#39;goog.labs.net.webChannel.WebChannelBaseTransport&#39;);
<a name="line109"></a>
<a name="line110"></a>
<a name="line111"></a>  /**
<a name="line112"></a>   * @private {Object.&lt;string, string&gt;} messageUrlParams_ Extra URL parameters
<a name="line113"></a>   * to be added to each HTTP request.
<a name="line114"></a>   */
<a name="line115"></a>  this.messageUrlParams_ =
<a name="line116"></a>      (opt_options &amp;&amp; opt_options.messageUrlParams) || null;
<a name="line117"></a>
<a name="line118"></a>  var messageHeaders = (opt_options &amp;&amp; opt_options.messageHeaders) || null;
<a name="line119"></a>  if (messageHeaders) {
<a name="line120"></a>    this.channel_.setExtraHeaders(messageHeaders);
<a name="line121"></a>  }
<a name="line122"></a>
<a name="line123"></a>  /**
<a name="line124"></a>   * @private {boolean} supportsCrossDomainXhr_ Whether to enable CORS.
<a name="line125"></a>   */
<a name="line126"></a>  this.supportsCrossDomainXhr_ =
<a name="line127"></a>      (opt_options &amp;&amp; opt_options.supportsCrossDomainXhr) || false;
<a name="line128"></a>};
<a name="line129"></a>goog.inherits(WebChannelBaseTransport.Channel, goog.events.EventTarget);
<a name="line130"></a>
<a name="line131"></a>
<a name="line132"></a>/**
<a name="line133"></a> * The channel handler.
<a name="line134"></a> *
<a name="line135"></a> * @type {WebChannelBase.Handler}
<a name="line136"></a> * @private
<a name="line137"></a> */
<a name="line138"></a>WebChannelBaseTransport.Channel.prototype.channelHandler_ = null;
<a name="line139"></a>
<a name="line140"></a>
<a name="line141"></a>/**
<a name="line142"></a> * Test path is always set to &quot;/url/test&quot;.
<a name="line143"></a> *
<a name="line144"></a> * @override
<a name="line145"></a> */
<a name="line146"></a>WebChannelBaseTransport.Channel.prototype.open = function() {
<a name="line147"></a>  this.channel_.connect(this.testUrl_, this.url_,
<a name="line148"></a>                        (this.messageUrlParams_ || undefined));
<a name="line149"></a>
<a name="line150"></a>  this.channelHandler_ = new WebChannelBaseTransport.Channel.Handler_(this);
<a name="line151"></a>  this.channel_.setHandler(this.channelHandler_);
<a name="line152"></a>  if (this.supportsCrossDomainXhr_) {
<a name="line153"></a>    this.channel_.setSupportsCrossDomainXhrs(true);
<a name="line154"></a>  }
<a name="line155"></a>};
<a name="line156"></a>
<a name="line157"></a>
<a name="line158"></a>/**
<a name="line159"></a> * @override
<a name="line160"></a> */
<a name="line161"></a>WebChannelBaseTransport.Channel.prototype.close = function() {
<a name="line162"></a>  this.channel_.disconnect();
<a name="line163"></a>};
<a name="line164"></a>
<a name="line165"></a>
<a name="line166"></a>/**
<a name="line167"></a> * The WebChannelBase only supports object types.
<a name="line168"></a> *
<a name="line169"></a> * @param {!goog.net.WebChannel.MessageData} message The message to send.
<a name="line170"></a> * @override
<a name="line171"></a> */
<a name="line172"></a>WebChannelBaseTransport.Channel.prototype.send = function(message) {
<a name="line173"></a>  goog.asserts.assert(goog.isObject(message), &#39;only object type expected&#39;);
<a name="line174"></a>  this.channel_.sendMap(message);
<a name="line175"></a>};
<a name="line176"></a>
<a name="line177"></a>
<a name="line178"></a>/**
<a name="line179"></a> * @override
<a name="line180"></a> */
<a name="line181"></a>WebChannelBaseTransport.Channel.prototype.disposeInternal = function() {
<a name="line182"></a>  this.channel_.setHandler(null);
<a name="line183"></a>  delete this.channelHandler_;
<a name="line184"></a>  this.channel_.disconnect();
<a name="line185"></a>  delete this.channel_;
<a name="line186"></a>
<a name="line187"></a>  WebChannelBaseTransport.Channel.base(this, &#39;disposeInternal&#39;);
<a name="line188"></a>};
<a name="line189"></a>
<a name="line190"></a>
<a name="line191"></a>
<a name="line192"></a>/**
<a name="line193"></a> * The message event.
<a name="line194"></a> *
<a name="line195"></a> * @param {!Array} array The data array from the underlying channel.
<a name="line196"></a> * @constructor
<a name="line197"></a> * @extends {goog.net.WebChannel.MessageEvent}
<a name="line198"></a> * @final
<a name="line199"></a> */
<a name="line200"></a>WebChannelBaseTransport.Channel.MessageEvent = function(array) {
<a name="line201"></a>  WebChannelBaseTransport.Channel.MessageEvent.base(this, &#39;constructor&#39;);
<a name="line202"></a>
<a name="line203"></a>  this.data = array;
<a name="line204"></a>};
<a name="line205"></a>goog.inherits(WebChannelBaseTransport.Channel.MessageEvent,
<a name="line206"></a>              goog.net.WebChannel.MessageEvent);
<a name="line207"></a>
<a name="line208"></a>
<a name="line209"></a>
<a name="line210"></a>/**
<a name="line211"></a> * The error event.
<a name="line212"></a> *
<a name="line213"></a> * @param {WebChannelBase.Error} error The error code.
<a name="line214"></a> * @constructor
<a name="line215"></a> * @extends {goog.net.WebChannel.ErrorEvent}
<a name="line216"></a> * @final
<a name="line217"></a> */
<a name="line218"></a>WebChannelBaseTransport.Channel.ErrorEvent = function(error) {
<a name="line219"></a>  WebChannelBaseTransport.Channel.ErrorEvent.base(this, &#39;constructor&#39;);
<a name="line220"></a>
<a name="line221"></a>  /**
<a name="line222"></a>   * Transport specific error code is not to be propagated with the event.
<a name="line223"></a>   */
<a name="line224"></a>  this.status = goog.net.WebChannel.ErrorStatus.NETWORK_ERROR;
<a name="line225"></a>};
<a name="line226"></a>goog.inherits(WebChannelBaseTransport.Channel.ErrorEvent,
<a name="line227"></a>              goog.net.WebChannel.ErrorEvent);
<a name="line228"></a>
<a name="line229"></a>
<a name="line230"></a>
<a name="line231"></a>/**
<a name="line232"></a> * Implementation of {@link WebChannelBase.Handler} interface.
<a name="line233"></a> *
<a name="line234"></a> * @param {!WebChannelBaseTransport.Channel} channel The enclosing WebChannel.
<a name="line235"></a> *
<a name="line236"></a> * @constructor
<a name="line237"></a> * @extends {WebChannelBase.Handler}
<a name="line238"></a> * @private
<a name="line239"></a> */
<a name="line240"></a>WebChannelBaseTransport.Channel.Handler_ = function(channel) {
<a name="line241"></a>  WebChannelBaseTransport.Channel.Handler_.base(this, &#39;constructor&#39;);
<a name="line242"></a>
<a name="line243"></a>  /**
<a name="line244"></a>   * @type {!WebChannelBaseTransport.Channel}
<a name="line245"></a>   * @private
<a name="line246"></a>   */
<a name="line247"></a>  this.channel_ = channel;
<a name="line248"></a>};
<a name="line249"></a>goog.inherits(WebChannelBaseTransport.Channel.Handler_, WebChannelBase.Handler);
<a name="line250"></a>
<a name="line251"></a>
<a name="line252"></a>/**
<a name="line253"></a> * @override
<a name="line254"></a> */
<a name="line255"></a>WebChannelBaseTransport.Channel.Handler_.prototype.channelOpened = function(
<a name="line256"></a>    channel) {
<a name="line257"></a>  goog.log.info(this.channel_.logger_,
<a name="line258"></a>      &#39;WebChannel opened on &#39; + this.channel_.url_);
<a name="line259"></a>  this.channel_.dispatchEvent(goog.net.WebChannel.EventType.OPEN);
<a name="line260"></a>};
<a name="line261"></a>
<a name="line262"></a>
<a name="line263"></a>/**
<a name="line264"></a> * @override
<a name="line265"></a> */
<a name="line266"></a>WebChannelBaseTransport.Channel.Handler_.prototype.channelHandleArray =
<a name="line267"></a>    function(channel, array) {
<a name="line268"></a>  goog.asserts.assert(array, &#39;array expected to be defined&#39;);
<a name="line269"></a>  this.channel_.dispatchEvent(
<a name="line270"></a>      new WebChannelBaseTransport.Channel.MessageEvent(array));
<a name="line271"></a>};
<a name="line272"></a>
<a name="line273"></a>
<a name="line274"></a>/**
<a name="line275"></a> * @override
<a name="line276"></a> */
<a name="line277"></a>WebChannelBaseTransport.Channel.Handler_.prototype.channelError = function(
<a name="line278"></a>    channel, error) {
<a name="line279"></a>  goog.log.info(this.channel_.logger_,
<a name="line280"></a>      &#39;WebChannel aborted on &#39; + this.channel_.url_ +
<a name="line281"></a>      &#39; due to channel error: &#39; + error);
<a name="line282"></a>  this.channel_.dispatchEvent(
<a name="line283"></a>      new WebChannelBaseTransport.Channel.ErrorEvent(error));
<a name="line284"></a>};
<a name="line285"></a>
<a name="line286"></a>
<a name="line287"></a>/**
<a name="line288"></a> * @override
<a name="line289"></a> */
<a name="line290"></a>WebChannelBaseTransport.Channel.Handler_.prototype.channelClosed = function(
<a name="line291"></a>    channel, opt_pendingMaps, opt_undeliveredMaps) {
<a name="line292"></a>  goog.log.info(this.channel_.logger_,
<a name="line293"></a>      &#39;WebChannel closed on &#39; + this.channel_.url_);
<a name="line294"></a>  this.channel_.dispatchEvent(goog.net.WebChannel.EventType.CLOSE);
<a name="line295"></a>};
<a name="line296"></a>
<a name="line297"></a>
<a name="line298"></a>/**
<a name="line299"></a> * @override
<a name="line300"></a> */
<a name="line301"></a>WebChannelBaseTransport.Channel.prototype.getRuntimeProperties = function() {
<a name="line302"></a>  return new WebChannelBaseTransport.ChannelProperties(this.channel_);
<a name="line303"></a>};
<a name="line304"></a>
<a name="line305"></a>
<a name="line306"></a>
<a name="line307"></a>/**
<a name="line308"></a> * Implementation of the {@link goog.net.WebChannel.RuntimeProperties}.
<a name="line309"></a> *
<a name="line310"></a> * @param {!WebChannelBase} channel The underlying channel object.
<a name="line311"></a> *
<a name="line312"></a> * @constructor
<a name="line313"></a> * @implements {goog.net.WebChannel.RuntimeProperties}
<a name="line314"></a> * @final
<a name="line315"></a> */
<a name="line316"></a>WebChannelBaseTransport.ChannelProperties = function(channel) {
<a name="line317"></a>  /**
<a name="line318"></a>   * The underlying channel object.
<a name="line319"></a>   *
<a name="line320"></a>   * @private {!WebChannelBase}
<a name="line321"></a>   */
<a name="line322"></a>  this.channel_ = channel;
<a name="line323"></a>
<a name="line324"></a>  /**
<a name="line325"></a>   * The flag to turn on/off server-side flow control.
<a name="line326"></a>   *
<a name="line327"></a>   * @private {boolean}
<a name="line328"></a>   */
<a name="line329"></a>  this.serverFlowControlEnabled_ = false;
<a name="line330"></a>
<a name="line331"></a>};
<a name="line332"></a>
<a name="line333"></a>
<a name="line334"></a>/**
<a name="line335"></a> * @override
<a name="line336"></a> */
<a name="line337"></a>WebChannelBaseTransport.ChannelProperties.prototype.getSpdyRequestLimit =
<a name="line338"></a>    function() {
<a name="line339"></a>  return this.channel_.getForwardChannelRequestPool().getMaxSize();
<a name="line340"></a>};
<a name="line341"></a>
<a name="line342"></a>
<a name="line343"></a>/**
<a name="line344"></a> * @override
<a name="line345"></a> */
<a name="line346"></a>WebChannelBaseTransport.ChannelProperties.prototype.setServerFlowControl =
<a name="line347"></a>    goog.abstractMethod;
<a name="line348"></a>
<a name="line349"></a>
<a name="line350"></a>/**
<a name="line351"></a> * @override
<a name="line352"></a> */
<a name="line353"></a>WebChannelBaseTransport.ChannelProperties.prototype.getNonAckedMessageCount =
<a name="line354"></a>    goog.abstractMethod;
<a name="line355"></a>});  // goog.scope
</pre>


</body>
</html>
